package cn.laike.modules.dev.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import cn.laike.common.utils.DateUtils;
import cn.laike.common.utils.PageUtils;
import cn.laike.common.utils.Query;

import cn.laike.modules.dev.dao.BreakfastCouponDao;
import cn.laike.modules.dev.entity.BreakfastCouponEntity;
import cn.laike.modules.dev.service.BreakfastCouponService;
import cn.laike.modules.sys.shiro.ShiroUtils;


@Service("breakfastCouponService")
public class BreakfastCouponServiceImpl extends ServiceImpl<BreakfastCouponDao, BreakfastCouponEntity> implements BreakfastCouponService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
    	Integer hotelId = ShiroUtils.getHotelId();
    	String name = (String)params.get("name");
    	String mobile = (String)params.get("mobile");
    	String startTime = (String)params.get("startTime");
    	String endTime = (String)params.get("endTime");
        Page<BreakfastCouponEntity> page = this.selectPage(
                new Query<BreakfastCouponEntity>(params).getPage(),
                new EntityWrapper<BreakfastCouponEntity>()
                .eq(ShiroUtils.isAdmin(),"uid", ShiroUtils.getUserId())
                .eq((hotelId != null && hotelId > 0), "hotel_id", hotelId)
                .between((StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime)),"used_date", startTime + " 00:00:00", endTime + " 23:59:59")
                //.ge("used_date", DateUtils.getStartTime())
                .like(StringUtils.isNotBlank(name),"name", name)
                .like(StringUtils.isNotBlank(mobile),"mobile", mobile)
                .orderBy("used_date", false)
        );

        return new PageUtils(page);
    }

	@Override
	public List<Map> queryMyCouponList(String openid, Integer pageNo, Integer pageSize) {
		return baseMapper.queryMyCouponList(openid, (pageNo - 1) * pageSize, pageSize);
	}

	@Override
	public List<Map> queryTodayCouponList(String openid) {
		return baseMapper.queryTodayCouponList(openid);
	}

	@Override
	public int updateCouponList(Date today) {
		return baseMapper.updateCouponList(today);
	}

	@Override
	public List<Double> statTotalMoney(Long uid, Integer hotelId, String startTime, String endTime) {
	
		return baseMapper.statTotalMoney(uid, hotelId, startTime, endTime);
	}

}
